package com.garden.web.context.config;

import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;

@Configuration
@ComponentScan(basePackages = "com.garden",
        excludeFilters = {@ComponentScan.Filter({Controller.class, ControllerAdvice.class, Configuration.class})})
@EnableAspectJAutoProxy(proxyTargetClass = true)
@PropertySource("classpath:system.properties")
public class AppConfig {
    @Bean
    public ReloadableResourceBundleMessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasenames("classpath:i18n/message", "classpath:i18n/validator");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }


    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Bean
    public ThreadPoolTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 最小线程数
        executor.setCorePoolSize(5);
        // 线程最大闲置时间
        executor.setKeepAliveSeconds(30000);
        // 最大线程数
        executor.setMaxPoolSize(10);
        // 最大任务队列数
        executor.setQueueCapacity(200);

        return executor;
    }
}